package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"log"
	"fmt"
)

type Event struct {
	Sd string `json:"sd"`
	SdType string `json:"sd_type"`
	Env string `json:"env"`
	Tname string `json:"tname"`
}

func jsonControl(c *gin.Context)  {
	var e []Event
	err :=c.BindJSON(&e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(len(e),e)
	c.JSON(http.StatusOK,gin.H{
		"message":"Ok",
		"data":"{k:v}",
	})
}

func getControl(c *gin.Context)  {
	c.JSON(http.StatusOK,gin.H{
		"message":"hello World",
		"data":"{k:v}",
	})
}
func kvHandler(c *gin.Context)  {
	fmt.Println(c.HandlerName())
	k,_ :=c.GetPostForm("k")
	c.JSON(http.StatusOK,gin.H{
		"k":k,
	})
}
func init()  {
	 r :=gin.Default()
	testGroup :=r.Group("/sd")
	{
		testGroup.GET("/get",getControl)
		testGroup.POST("/post",jsonControl)
	}
}
func main()  {
	r :=gin.Default()
	testGroup :=r.Group("/sd")
	{
		testGroup.GET("/get",getControl)
		testGroup.POST("/post",jsonControl)
		testGroup.POST("/kv",kvHandler)
	}
	r.Run(":8888")
}
